package org.example.controller;

import org.example.model.Department;
import org.example.model.Teacher;
import org.example.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class DepartmentController {
        @Autowired
        private DepartmentService departmentService;
        @RequestMapping(value = "/queryDepartment")
        public List<Department> queryDepartmentList(){
            //1.调用业务逻辑层中的查询方法
            List<Department> departmentList = departmentService.queryDepartment();
            //2.返回查询结果
            return departmentList;
        }


        @PostMapping(value = "/addDepartment")
        public int addDepartment(@RequestBody Department department){
            //调用业务逻辑层中的方法，实现添加操作
            return departmentService.addDepartment(department);
        }


        @RequestMapping("/updateDepartment")
        public int updateDepartment(@RequestBody Department department){
            //调用业务逻辑层中的修改方法
            return departmentService.updateDepartment(department);
        }

        @RequestMapping("/deleteDepartmentById")
        public int deleteDepartmentById(int dId){
            return departmentService.deleteDepartment(dId);
        }

        @RequestMapping("/queryDepartmentDept")
        public List<Map<String ,Object>> queryDepartmentDept(){
            return departmentService.queryDepartmentDept();
        }

        @RequestMapping("/queryDepartmentByID")
        public Department queryDepartmentByID(int dId){
            return departmentService.queryDepartmentById(dId);
        }


}